import Cookies from 'js-cookie';

const user = {
    state: {
        nickname: '',
        avatar: '',
        isFullScreen: true,
        isRoute: null
    },
    mutations: {
        setIsFullScreen(state, flag) {
            state.isFullScreen = flag;
        },
        setRoute(state, v) {
            state.isRoute = v;
        },
        setUserInfo(state, v) {
            state.nickname = v.nickname;
            state.avatar = v.avatar;
            sessionStorage.nickname = v.nickname;
            sessionStorage.avatar = v.avatar;
        },
        setNickname(state, v) {
            state.nickname = v;
            sessionStorage.nickname = v;
        },
        setAvatar(state, v) {
            state.avatar = v;
            sessionStorage.avatar = v;
        },
        logout() {
            Cookies.remove('userInfo');
            // 清空打开的页面等数据 保留语言、主题等配置数据
            let lang = sessionStorage.lang,
                theme = sessionStorage.theme;
            sessionStorage.clear();
            sessionStorage.lang = lang;
            sessionStorage.theme = theme;
        }
    }
};

export default user;
